

ac.skill('一键整理'){
    art = [[ReplaceableTextures\CommandButtons\BTNPickUpItem.blp]],
    art = [[图标\XS_wpzl.blp]],
    tip = [[整理地上物品]],
    on_add = function(self)
        local hero = self.owner
        local player = hero.owner
        --不整理区域
        local rect1 = ac.rect.j_rect('item'..player.id)
        player.item_saverect = rect1
    end,
    on_cast_shot = function(self)
        local hero = self.owner
        local player = hero.owner
        for it in ac.selector('item')
            : rect(ac.rect.map)
            : loop()
        do
            if it.owner_player==player then
                collate_item(hero,it)
            end
        end
    end
}


ac.skill('一键拾取'){
    art = [[ReplaceableTextures\CommandButtons\BTNPickUpItem.blp]],
    art = [[图标\XS_fwsq.blp]],
    tip = [[拾取周围所有装备]],
    targettype = '点',
    range = 9999,
    is_selector = true,
    area = 300,
    on_cast_shot = function(self)
        local hero = self.owner
        local point = self.target:get_point()
        for it in ac.selector('item')
            : range(point,self.area)
            : loop()
        do
            it:give(hero)
        end
    end
}


ac.skill('一键丢弃'){
    art = [[ReplaceableTextures\CommandButtons\BTNCryptFiendBurrow.blp]],
    art = [[图标\XS_wpdq.blp]],
    tip = [[将身上的装备全部丢弃到指定点]],
    targettype = '点',
    range = 9999,
    on_cast_shot = function(self)
        local hero = self.owner
        local point = self.target:get_point()
        for _,item in ipairs(hero:get_items()) do
            item:discard(point)
        end
    end
}

ac.skill('合成装备'){
    art = [[ReplaceableTextures\CommandButtons\BTNAdvStruct.blp]],
    art = [[图标\XS_hczb.blp]],
    tip = [[将地上的装备进行合成]],
    range = 9999,
    area = 300,
    cool = 0.2,
    is_selector = true,
    targettype = '点',
    on_cast_shot = function(self,point)
        local unit = self.owner
        local items = ac.selector('item'):range(point,300):get()
        unit:notify('单位-合成装备', unit,items,point)
    end
}


ac.skill('重铸装备'){
    art = [[ReplaceableTextures\CommandButtons\BTNAdvStruct.blp]],
    art = [[图标\XS_zbcz.blp]],
    tip = [[重铸一件装备（冷却360秒）]],
    cool = 360,
    range = 9999,
    targettype = '物体',
    allowtype = '物品',
    on_cast_shot = function(self,item)
        if item.item_class~='装备' then
            self:set_cd(1)
            return
        end
        local unit = self.owner
        local player = unit.owner
        local lv = item.item_level or 0
        local name = item.name
        while name==item.name do
            name = random_item_name(lv)
        end
        item:remove()
        unit:add_item(name,{owner_player = player})
    end
}

ac.skill('助手机制'){
    on_add = function(self)
        local unit = self.owner
        local player = unit.owner
        local hero = player.hero
        self:gc(unit:event '单位-发布命令' (function(_, _, orderid, target)
            local order = Order[orderid]
            if order=='smart' then
                if unit:get_point()*target:get_point()>500 then
                    unit:issue_order('stop')
                    unit:set_point(target:get_point())
                end
            end
        end))
        
        self:gc(hero:event '单位-右键双击物品' (function(_, _, item)
            if unit:is_alive() and #unit:get_items()<6 then
                item:discard()
                item:give(unit)
            end
        end))
        self:gc(unit:event '单位-右键双击物品' (function(_, _, item)
            if hero:is_alive() and #hero:get_items()<6 then
                item:discard()
                item:give(hero)
            end
        end))
        
    end
}




register_hero(function(player,hero)
    local point = player.item_point
    local pet = player:create_unit('助手',hero:get_point())
    player.pet = pet
    pet.shop_tip = '我是一个鸽子，咕咕咕！'
    pet:add_restriction '无敌'
    pet:add_skill('助手机制')
    pet:add_skill('一键整理','英雄')
    pet:add_skill('一键拾取','英雄')
    pet:add_skill('一键丢弃','英雄')
    pet:add_skill('合成装备','英雄')
    pet:add_skill('重铸装备','英雄')
    
    
end)